/* eslint-disable func-call-spacing */
/* eslint-disable space-before-function-paren */
/* eslint-disable eol-last */
/* eslint-disable indent */
import Vue from 'vue'
import VueRouter from 'vue-router'
import {
    routerMode
} from '../config/env'

// import Login from '@/views/Login/Login'
// import Shop from '@/views/Shop/Shop'
// import ShopGoods from '@/views/Shop/ShopGoods/ShopGoods'
// import ShopInfo from '@/views/Shop/ShopInfo/ShopInfo'
// import ShopRatings from '@/views/Shop/ShopRatings/ShopRatings'

// import MSite from '@/views/MSite/MSite'
// import Search from '@/views/Search/Search'
// import Person from '@/views/Person/Person'
// import Order from '@/views/Order/Order'
const MSite = () =>
    import ('@/views/MSite/MSite')
const Search = () =>
    import ('@/views/Search/Search')
const Person = () =>
    import ('@/views/Person/Person')
const Order = () =>
    import ('@/views/Order/Order')
const Login = () =>
    import ('@/views/Login/Login')
const Shop = () =>
    import ('@/views/Shop/Shop')
const ShopGoods = () =>
    import ('@/views/Shop/ShopGoods/ShopGoods')
const ShopInfo = () =>
    import ('@/views/Shop/ShopInfo/ShopInfo')
const ShopRatings = () =>
    import ('@/views/Shop/ShopRatings/ShopRatings')
Vue.use(VueRouter)

const routes = [{
        path: '/',
        redirect: '/msite'
    }, {
        path: '/msite',
        component: MSite, // 返回路由组件的函数,只有执行此函数才会加载路由组件,这个函数在请求对应的路由路径时才会执行
        meta: {
            showFooter: true
        }
    }, {
        path: '/search',
        component: Search,
        meta: {
            showFooter: true
        }
    }, {
        path: '/order',
        component: Order,
        meta: {
            showFooter: true
        }
    }, {
        path: '/person',
        component: Person,
        meta: {
            showFooter: true
        }
    }, {
        path: '/login',
        component: Login
    }, {
        path: '/shop',
        component: Shop,
        children: [{
                path: '/shop/goods',
                component: ShopGoods
            },
            {
                path: '/shop/ratings',
                component: ShopRatings
            },
            {
                path: '/shop/info',
                component: ShopInfo
            },
            {
                path: '',
                redirect: '/shop/goods'
            }
        ]
    }

]

const router = new VueRouter({
    routes,
    mode: routerMode,
    strict: process.env.NODE_ENV !== 'production',
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        } else {
            if (from.meta.keepAlive) {
                from.meta.savedPosition = document.body.scrollTop
            }
            return {
                x: 0,
                y: to.meta.savedPosition || 0
            }
        }
    }
})

export default router